package com.example.springboottest.example.netty.echo;

import com.example.springboottest.student.model.Student;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCountUtil;

@ChannelHandler.Sharable
public class EchoServerOutboundHandler2 extends ChannelOutboundHandlerAdapter {
    @Override
    public void write(ChannelHandlerContext ctx,
                      Object msg, ChannelPromise promise) {
        System.out.println("EchoServerOutboundHandler2.write");
        ByteBuf out = Unpooled.copiedBuffer("服务器发送个出栈消息", CharsetUtil.UTF_8);
        ctx.write(out);
        ReferenceCountUtil.release(msg);
        promise.setSuccess();
    }
}
